package com.wyzz.hr.bo.impl;

import com.wyzz.hr.action.SalaryConfigAssist;
import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.Constants;
import com.wyzz.hr.base.Status;
import com.wyzz.hr.bo.IEmpSalaryAcctitemsBo;
import com.wyzz.hr.bo.IEmployeeBo;
import com.wyzz.hr.bo.ISalaryconfBo;
import com.wyzz.hr.dao.ISalaryconfDAO;
import com.wyzz.hr.dao.IStatusDAO;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Empsalaryacctitems;
import com.wyzz.hr.pojo.Empsalaryconfig;
import com.wyzz.hr.pojo.Jobgrade;
import com.wyzz.hr.spring.SpringBeanFactory;
import com.wyzz.hr.util.InterpreterExecuteContext;
import com.wyzz.hr.util.Pager;
import com.wyzz.hr.util.StringUtil;

import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.*;
import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.FetchMode;
import org.hibernate.criterion.*;

public class SalaryconfBoImpl implements ISalaryconfBo, Constants, Status {

	public SalaryconfBoImpl() {
	}

	public boolean deleteSalaryconf(String id, Employee emp) {
		Empsalaryconfig salary = (Empsalaryconfig) salaryconfDAO.loadObject(
				com.wyzz.hr.pojo.Empsalaryconfig.class, id,
				new String[] { "employee" }, new boolean[0]);
		if (salary == null) {
			return false;
		} else {
			salaryconfDAO.deleteObject(salary);
			Employee employee = salary.getEmployee();
			employee.setConfig(null);
			employee.setEmpLastChangeBy(emp);
			employee.setEmpLastChangeTime(new Date());
			salaryconfDAO.updateObject(employee);
			return true;
		}
	}

	public boolean saveOrupdateObject(Object obj) {
		try {
			salaryconfDAO.saveOrupdate(obj);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public boolean saveOrupdate(Collection objs) {
		try {
			salaryconfDAO.saveOrupdate(objs);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public List getObjects(Class clas, String fetch[]) {
		List result = salaryconfDAO.getObjects(clas, fetch);
		return result;
	}

	public Object getObject(Class clas, Object id, String fetch[]) {
		Object result = salaryconfDAO.loadObject(clas, id, fetch,
				new boolean[0]);
		return result;
	}

	public Empsalaryconfig loadSalaryconf(Object id, String fetch[]) {
		return (Empsalaryconfig) salaryconfDAO.loadObject(
				com.wyzz.hr.pojo.Empsalaryconfig.class, id, fetch,
				new boolean[0]);
	}

	public boolean saveOrUpdateEsc(Empsalaryconfig config, String empNo,
			Employee employee) {
		try {
			Date today = new Date();
			if (config.getEscCreateTime() == null) {
				config.setEscCreateTime(today);
				config.setEscCreateBy(empNo);
			}
			config.setEscLastChangeTime(today);
			config.setEscLastChangeBy(empNo);
			config.encryEmpSalaryConf(config);
			salaryconfDAO.saveOrupdate(config);
			employee.setConfig(config);
			employee.setEmpLastChangeTime(today);
			employee.setEmpLastChangeBy(new Employee(empNo));
			salaryconfDAO.updateObject(employee);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public boolean insertSalaryconf(Empsalaryconfig salary, String empNo,
			Employee employee) {
		if (loadSalaryconf(salary.getId(), new String[0]) != null) {
			return false;
		} else {
			Date today = new Date();
			salary.setEscCreateTime(today);
			salary.setEscLastChangeTime(today);
			salary.setEscCreateBy(empNo);
			salary.setEscLastChangeBy(empNo);
			salary.encryEmpSalaryConf(salary);
			salaryconfDAO.saveObject(salary);
			employee.setConfig(salary);
			employee.setEmpLastChangeTime(new Date());
			employee.setEmpLastChangeBy(new Employee(empNo));
			salaryconfDAO.updateObject(employee);
			return true;
		}
	}

	public boolean updateSalaryconf(Empsalaryconfig salaryconf, String empNo) {
		try {
			salaryconf.setEscLastChangeBy(empNo);
			salaryconf.setEscLastChangeTime(new Date());
			salaryconf.encryEmpSalaryConf(salaryconf);
			salaryconfDAO.updateObject(salaryconf);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public Employee findConfigByEmpId(String id) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Employee.class);
		detachedCriteria.setFetchMode("empType", FetchMode.JOIN);
		detachedCriteria.setFetchMode("config", FetchMode.JOIN);
		detachedCriteria.setFetchMode("config.escJobgrade", FetchMode.JOIN);
		detachedCriteria.add(Restrictions.eq(Employee.PROP_ID, id));
		List result = salaryconfDAO.findByCriteria(detachedCriteria);
		Employee employeeFromDB = null;
		if (result != null)
			employeeFromDB = (Employee) result.get(0);
		return employeeFromDB;
	}

	public Map findSalaryConfigByNoPage(DetachedCriteria dc, Pager page,
			Employee emp) {
		dc.setFetchMode("empType", FetchMode.JOIN);
		dc.setFetchMode("empDeptNo", FetchMode.JOIN);
		dc.setFetchMode("empLocationNo", FetchMode.JOIN);
		dc.createAlias("config", "config", 1);
		dc.createAlias("config.escJobgrade", "config.escJobgrade", 1);
		dc.createAlias("config.escEsavId", "config.escEsavId", 1);
		dc.createAlias("config.escEsavId.esavEsac",
				"config.escEsavId.esavEsac", 1);
		dc.add(Restrictions.isNotNull("config"));
		dc.addOrder(Order.asc("empDistinctNo"));
		List result = salaryconfDAO.findByCriteria(dc);
		if (result == null || result.size() == 0)
			return null;
		Map dataDefMap = getAcctDataDefCache();
		Map resultMap = new HashMap();
		String accountName;
		List tmpListArray[];
		for (Iterator i$ = result.iterator(); i$.hasNext(); resultMap.put(
				accountName, tmpListArray)) {
			Employee employee = (Employee) i$.next();
			Empsalaryconfig cfg = employee.getConfig();
			cfg.decryEmpSalaryConf(cfg);
			accountName = cfg.getEscEsavId().getEsavEsac().getEsacName();
			tmpListArray = (List[]) resultMap.get(accountName);
			if (tmpListArray == null) {
				tmpListArray = (new ArrayList[] { new ArrayList(),
						new ArrayList() });
				tmpListArray[0].add("\u5DE5\u53F7");
				tmpListArray[0].add("\u59D3\u540D");
				tmpListArray[0].add("\u90E8\u95E8");
				tmpListArray[0].add("\u7528\u5DE5\u5F62\u5F0F");
				tmpListArray[0].add("\u5DE5\u4F5C\u5730\u533A");
				tmpListArray[0].add("\u72B6\u6001");
				tmpListArray[0].add("\u94F6\u884C\u5E10\u53F7");
				tmpListArray[0].add("\u94F6\u884C\u5F00\u6237\u884C");
				tmpListArray[0].add("\u6210\u672C\u4E2D\u5FC3");
				tmpListArray[0].add("\u85AA\u8D44\u7EA7\u522B");
				tmpListArray[0].add("\u85AA\u8D44\u5E10\u5957");
				tmpListArray[0].addAll((Collection) dataDefMap.get(cfg
						.getEscEsavId().getId()));
			}
			List contentList = tmpListArray[1];
			SalaryConfigAssist salaryConfigAssist = new SalaryConfigAssist();
			salaryConfigAssist.setEmpNo(employee.getEmpDistinctNo());
			salaryConfigAssist.setEmpName(employee.getEmpName());
			salaryConfigAssist.setEmpDept(employee.getEmpDeptNo()
					.getDepartmentName());
			salaryConfigAssist.setEmpType(employee.getEmpType()
					.getEmptypeName());
			salaryConfigAssist.setEmpLocation(employee.getEmpLocationNo()
					.getLocationName());
			salaryConfigAssist
					.setEmpStatus(employee.getEmpStatus().intValue() != 0 ? "\u5728\u804C"
							: "\u79BB\u804C");
			salaryConfigAssist.setSalaryLevel(cfg.getEscJobgrade()
					.getJobGradeName());
			salaryConfigAssist.setSalaryAccept(cfg.getEscEsavId().getId());
			salaryConfigAssist.setAcceptName(cfg.getEscEsavId().getEsavEsac()
					.getEsacName());
			salaryConfigAssist.setEmpBankName(cfg.getEscBankName());
			salaryConfigAssist.setEmpCount(cfg.getEscBankAccountNo());
			salaryConfigAssist.setCostCenter(cfg.getEscCostCenter());
			String tmpTitle = (String) tmpListArray[0].get(tmpListArray[0]
					.size() - 1);
			int size = Integer.valueOf(tmpTitle.split("-")[0].substring(1))
					.intValue();
			salaryConfigAssist.setList(getExportList(cfg, size));
			contentList.add(salaryConfigAssist);
		}

		return resultMap;
	}

	private List getExportList(Empsalaryconfig cfg, int size) {
		List list = new ArrayList();
		for (int i = 1; i <= size; i++)
			try {
				BigDecimal tmp = (BigDecimal) PropertyUtils.getProperty(cfg,
						(new StringBuilder()).append("escColumn").append(i)
								.toString());
				list.add(tmp);
			} catch (Exception e) {
				e.printStackTrace();
			}

		return list;
	}

	private Map getAcctDataDefCache() {
		Map cache = new HashMap();
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empsalaryacctitems.class);
		detachedCriteria.addOrder(Order.asc("esaiDataSeq"));
		detachedCriteria.setFetchMode("esaiEsdd", FetchMode.JOIN);
		List allItems = salaryconfDAO.findByCriteria(detachedCriteria);
		Empsalaryacctitems item;
		List tmpList;
		for (Iterator i$ = allItems.iterator(); i$.hasNext(); cache.put(item
				.getEsaiEsav().getId(), tmpList)) {
			item = (Empsalaryacctitems) i$.next();
			tmpList = (List) cache.get(item.getEsaiEsav().getId());
			if (tmpList == null)
				tmpList = new ArrayList();
			tmpList.add((new StringBuilder()).append("A").append(
					item.getEsaiDataSeq()).append("-").append(
					item.getEsaiEsdd().getEsddName()).toString());
		}

		return cache;
	}

	public List findConfig(DetachedCriteria dc, Pager page) {
		if (page == null) {
			BaseAction.addOrders(dc, null, new String[] { (new StringBuilder())
					.append("emp.").append(Employee.PROP_EMP_DISTINCT_NO)
					.append("-up").toString() });
			return salaryconfDAO.findByCriteria(dc);
		} else {
			BaseAction.addOrders(dc, page, new String[] { (new StringBuilder())
					.append("emp.").append(Employee.PROP_EMP_DISTINCT_NO)
					.append("-up").toString() });
			page.splitPage(dc);
			return salaryconfDAO.findByCriteria(dc, page.getPageSize(), page
					.getCurrentPage());
		}
	}

	public List findSalaryConfig(DetachedCriteria dc, Pager page, Employee emp) {
		dc.createAlias("empType", "empType", 1);
		dc.createAlias("empDeptNo", "empDeptNo", 1);
		dc.createAlias("config", "config", 1);
		dc.createAlias("config.escJobgrade", "escJobgrade", 1);
		dc.createAlias("config.escEsavId", "escEsavId", 1);
		dc.createAlias("escEsavId.esavEsac", "esavEsac", 1);
		page.splitPage(dc);
		List empConfigList = salaryconfDAO.findByCriteria(dc, page
				.getPageSize(), page.getCurrentPage());
		IEmpSalaryAcctitemsBo empSalaryAcctitemsBo = (IEmpSalaryAcctitemsBo) SpringBeanFactory
				.getBean("empsalaryacctitemsBo");
		Map itemsMap = empSalaryAcctitemsBo
				.getItemsByEmployeeConf(empConfigList);
		Iterator it = empConfigList.iterator();
		do {
			if (!it.hasNext())
				break;
			Employee employeeTemp = (Employee) it.next();
			Empsalaryconfig esc = employeeTemp.getConfig();
			if (esc != null)
				try {
					esc.decryEmpSalaryConf(esc);
					List acctList = (List) itemsMap.get(esc.getEscEsavId()
							.getId());
					calcSalaryConfByType(acctList, esc);
					employeeTemp.setConfig(esc);
				} catch (Exception e) {
					e.printStackTrace();
				}
		} while (true);
		return empConfigList;
	}

	public List getSalaryConfigByAcctVersion(String acctversionId) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empsalaryconfig.class);
		detachedCriteria.setFetchMode(Empsalaryconfig.PROP_EMPLOYEE,
				FetchMode.JOIN);
		detachedCriteria
				.setFetchMode("employee.empBenefitType", FetchMode.JOIN);
		detachedCriteria.setFetchMode("employee.benefit", FetchMode.JOIN);
		detachedCriteria.setFetchMode("escJobgrade", FetchMode.JOIN);
		detachedCriteria.add(Restrictions.eq("escEsavId.id", acctversionId));
		List configList = salaryconfDAO.findByCriteria(detachedCriteria);
		if (configList.size() > 0) {
			Empsalaryconfig config;
			for (Iterator i$ = configList.iterator(); i$.hasNext(); config
					.decryEmpSalaryConf(config))
				config = (Empsalaryconfig) i$.next();

		}
		return configList;
	}

	public int hasSalaryConfigByAcctVersion(String acctversionId) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empsalaryconfig.class);
		detachedCriteria.add(Restrictions.eq("escEsavId.id", acctversionId));
		detachedCriteria.setProjection(Projections.rowCount());
		List list = salaryconfDAO.findByCriteria(detachedCriteria);
		return ((Integer) list.get(0)).intValue();
	}

	public List getConfigByIds(String ids[]) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empsalaryconfig.class);
		detachedCriteria.setFetchMode("employee", FetchMode.JOIN);
		detachedCriteria
				.setFetchMode("employee.empBenefitType", FetchMode.JOIN);
		detachedCriteria.setFetchMode("employee.benefit", FetchMode.JOIN);
		detachedCriteria.setFetchMode("escJobgrade", FetchMode.JOIN);
		detachedCriteria.setFetchMode("escEsavId", FetchMode.JOIN);
		detachedCriteria.add(Restrictions.in(Empsalaryconfig.PROP_ID, ids));
		List salaryConfigList = salaryconfDAO.findByCriteria(detachedCriteria);
		return salaryConfigList;
	}

	public boolean calcSalaryConfByTypes(List empConfigList) {
		IEmpSalaryAcctitemsBo empSalaryAcctitemsBo = (IEmpSalaryAcctitemsBo) SpringBeanFactory
				.getBean("empsalaryacctitemsBo");
		Map itemsMap = empSalaryAcctitemsBo
				.getItemsByEmployeeConf(empConfigList);
		Iterator i$ = empConfigList.iterator();
		do {
			if (!i$.hasNext())
				break;
			Employee emp = (Employee) i$.next();
			if (emp.getConfig() != null) {
				Empsalaryconfig esc = emp.getConfig();
				esc.decryEmpSalaryConf(esc);
				calcSalaryConfByType((List) itemsMap.get(emp.getConfig()
						.getEscEsavId().getId()), esc);
			}
		} while (true);
		return true;
	}

	public Empsalaryconfig calcSalaryConfByType(List acctList,
			Empsalaryconfig esc) {
		if (acctList == null || acctList.size() <= 0 || esc == null)
			return null;
		try {
			List sumList = new ArrayList();
			for (int i = 0; i <= 20; i++)
				sumList.add(new BigDecimal(0));

			Class ownerClass = esc.getClass();
			int i = 0;
			for (int j = acctList.size(); i < j; i++) {
				Empsalaryacctitems esai = (Empsalaryacctitems) acctList.get(i);
				Method espMethod = ownerClass.getMethod((new StringBuilder())
						.append("getEscColumn").append(esai.getEsaiDataSeq())
						.toString(), new Class[0]);
				BigDecimal temp = (BigDecimal) espMethod.invoke(esc,
						new Object[0]);
				if (temp != null)
					sumList.set(
							esai.getEsaiEsdd().getEsddDataType().intValue(),
							((BigDecimal) sumList.get(esai.getEsaiEsdd()
									.getEsddDataType().intValue())).add(temp));
			}

			esc.setShowColumn1((BigDecimal) sumList.get(1));
			esc.setShowColumn4((BigDecimal) sumList.get(4));
			esc.setShowColumn7((BigDecimal) sumList.get(7));
			esc.setShowColumn8((BigDecimal) sumList.get(8));
			esc.setShowColumn17((BigDecimal) sumList.get(17));
			esc.setShowColumn18((BigDecimal) sumList.get(18));
			esc.setShowColumn19((BigDecimal) sumList.get(19));
			esc.setShowColumn20((BigDecimal) sumList.get(20));
			esc.setShowColumn10((BigDecimal) sumList.get(10));
			esc.setShowColumn11((BigDecimal) sumList.get(11));
			esc.setShowColumn12((BigDecimal) sumList.get(12));
			esc.setShowColumn13((BigDecimal) sumList.get(13));
			esc.setShowColumn14((BigDecimal) sumList.get(14));
			esc.setShowColumn15((BigDecimal) sumList.get(15));
			esc.setShowColumn16((BigDecimal) sumList.get(16));
			return esc;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public String[][] findSalaryBenefitValue(String empId) {
		IEmployeeBo empBo = (IEmployeeBo) SpringBeanFactory.getBean("empBo");
		String fetch[] = { "config" };
		Employee emp = empBo.loadEmp(empId, fetch);
		if (emp == null)
			return (String[][]) null;
		Empsalaryconfig esc = emp.getConfig();
		if (esc != null) {
			esc.decryEmpSalaryConf(esc);
			IEmpSalaryAcctitemsBo empSalaryAcctitemsBo = (IEmpSalaryAcctitemsBo) SpringBeanFactory
					.getBean("empsalaryacctitemsBo");
			List acctList = empSalaryAcctitemsBo.getItemsByAcctversion(esc
					.getEscEsavId().getId());
			calcSalaryConfByType(acctList, esc);
			String returnValue[][] = new String[7][2];
			returnValue[0][0] = "\u4E2A\u4EBA\u7F34\u793E\u4FDD";
			returnValue[0][1] = esc.getShowColumn10().toString();
			returnValue[1][0] = "\u516C\u53F8\u4EE3\u7F34\u793E\u4FDD";
			returnValue[1][1] = esc.getShowColumn11().toString();
			returnValue[2][0] = "\u4E2A\u4EBA\u7F34\u516C\u79EF\u91D1";
			returnValue[2][1] = esc.getShowColumn12().toString();
			returnValue[3][0] = "\u516C\u53F8\u4EE3\u7F34\u516C\u79EF\u91D1";
			returnValue[3][1] = esc.getShowColumn13().toString();
			returnValue[4][0] = "\u5176\u4ED6\u798F\u5229\u9879";
			returnValue[4][1] = esc.getShowColumn14().toString();
			returnValue[5][0] = "\u4E2A\u4EBA\u7F34\u793E\u4FDD\u603B\u989D";
			returnValue[5][1] = esc.getShowColumn15().toString();
			returnValue[6][0] = "\u516C\u53F8\u4EE3\u7F34\u793E\u4FDD\u603B\u989D";
			returnValue[6][1] = esc.getShowColumn16().toString();
			return returnValue;
		} else {
			return (String[][]) null;
		}
	}

	public String batchUpdateConfig(String currEmpNo, List configList) {
		if (configList == null || configList.size() == 0)
			return "";
		Date changeTime = new Date();
		String concatStr = "";
		Empsalaryconfig config;
		Employee emp;
		for (Iterator i$ = configList.iterator(); i$.hasNext(); config
				.setEmployee(new Employee(emp.getId()))) {
			config = (Empsalaryconfig) i$.next();
			config.setEscLastChangeBy(currEmpNo);
			config.setEscLastChangeTime(changeTime);
			config.encryEmpSalaryConf(config);
			concatStr = StringUtil.addConcatStr(concatStr, "\u3001",
					new Object[] { config.getEmployee().getEmpName() });
			emp = config.getEmployee();
		}

		saveOrupdate(configList);
		return concatStr;
	}

	public List getConfigItemsById(String configId) {
		Empsalaryconfig config = loadSalaryconf(configId, new String[0]);
		if (config == null)
			return null;
		config.decryEmpSalaryConf(config);
		IEmpSalaryAcctitemsBo empSalaryAcctitemsBo = (IEmpSalaryAcctitemsBo) SpringBeanFactory
				.getBean("empsalaryacctitemsBo");
		List esacItems = empSalaryAcctitemsBo.getItemsByAcctversion(config
				.getEscEsavId().getId());
		Empsalaryacctitems item = new Empsalaryacctitems();
		Class ownerClass = config.getClass();
		try {
			for (int i = 0; i < esacItems.size(); i++) {
				item = (Empsalaryacctitems) esacItems.get(i);
				Method escMethod = ownerClass.getMethod((new StringBuilder())
						.append("getEscColumn").append(item.getEsaiDataSeq())
						.toString(), new Class[0]);
				item.setItemConfigValue((BigDecimal) escMethod.invoke(config,
						new Object[0]));
				item.setItemValue((BigDecimal) escMethod.invoke(config,
						new Object[0]));
			}

		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return esacItems;
	}

	public Boolean deleteSalaryConfig(String esavId) {
		try {
			String hql = (new StringBuilder()).append(
					"delete Empsalaryconfig as esc where esc.escEsavId.id='")
					.append(esavId).append("'").toString();
			salaryconfDAO.exeHql(hql);
			return Boolean.valueOf(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Boolean.valueOf(false);
	}

	public List changeSalaryConfig(String acctversionId, Map oldMap,
			List newItems) {
		List configList = getSalaryConfigByAcctVersion(acctversionId);
		if (configList.size() == 0) {
			return configList;
		} else {
			shuffleSalaryConfig(configList, oldMap, newItems);
			interpretConfig((Empsalaryconfig[]) configList
					.toArray(new Empsalaryconfig[configList.size()]));
			salaryconfigSimplify(configList);
			return configList;
		}
	}

	private Boolean shuffleSalaryConfig(List salaryConfigList, Map fromMap,
			List toItems) {
		for (int i = 0; i < salaryConfigList.size(); i++)
			try {
				Empsalaryconfig salaryconfig = (Empsalaryconfig) ((Empsalaryconfig) salaryConfigList
						.get(i)).clone();
				String dataDefId = new String();
				for (int j = 0; j < toItems.size(); j++) {
					dataDefId = ((Empsalaryacctitems) toItems.get(j))
							.getEsaiEsdd().getEsddId();
					Integer fromPos = (Integer) fromMap.get(dataDefId);
					if (fromPos != null
							&& ((Empsalaryacctitems) toItems.get(j))
									.getEsaiDataIsCalc().intValue() == 0) {
						if (fromPos.intValue() == j)
							continue;
						Object escValue = PropertyUtils.getProperty(
								salaryconfig, (new StringBuilder()).append(
										"escColumn").append(
										fromPos.intValue() + 1).toString());
						if (escValue == null)
							PropertyUtils.setProperty(salaryConfigList.get(i),
									(new StringBuilder()).append("escColumn")
											.append(j + 1).toString(),
									new BigDecimal("0.00"));
						else
							PropertyUtils.setProperty(salaryConfigList.get(i),
									(new StringBuilder()).append("escColumn")
											.append(j + 1).toString(),
									((BigDecimal) escValue).setScale(2));
					} else {
						PropertyUtils.setProperty(salaryConfigList.get(i),
								(new StringBuilder()).append("escColumn")
										.append(j + 1).toString(),
								new BigDecimal("0.00"));
					}
				}

				((Empsalaryconfig) salaryConfigList.get(i))
						.setAcctItems(toItems);
			} catch (Exception e) {
				e.printStackTrace();
				return Boolean.valueOf(false);
			}

		return Boolean.valueOf(true);
	}

	public void interpretConfig(Empsalaryconfig configArr[]) {
		if (configArr == null || configArr.length == 0) {
			return;
		} else {
			InterpreterExecuteContext context = new InterpreterExecuteContext(
					null);
			context.execute(configArr);
			return;
		}
	}

	private Boolean salaryconfigSimplify(List salaryConfigList) {
		if (salaryConfigList == null || salaryConfigList.size() == 0)
			return Boolean.valueOf(false);
		Empsalaryconfig config;
		for (Iterator i$ = salaryConfigList.iterator(); i$.hasNext(); config
				.encryEmpSalaryConf(config)) {
			config = (Empsalaryconfig) i$.next();
			config.setEmployee(new Employee(config.getEmployee().getId()));
			config
					.setEscJobgrade(new Jobgrade(config.getEscJobgrade()
							.getId()));
		}

		return Boolean.valueOf(true);
	}

	public List getAllCostCenter() {
		String hql = "select distinct escCostCenter from Empsalaryconfig where escCostCenter is not null and escCostCenter !=''";
		List costCenterList = salaryconfDAO.exeHqlList(hql);
		return costCenterList;
	}

	public List getEmployeeWithConfig(String empIds[]) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Employee.class);
		detachedCriteria.setFetchMode(Employee.PROP_CONFIG, FetchMode.JOIN);
		detachedCriteria.setFetchMode((new StringBuilder()).append("config.")
				.append(Empsalaryconfig.PROP_ESC_JOBGRADE).toString(),
				FetchMode.JOIN);
		detachedCriteria.setFetchMode((new StringBuilder()).append("config.")
				.append(Empsalaryconfig.PROP_ESC_ESAV_ID).toString(),
				FetchMode.JOIN);
		detachedCriteria.setFetchMode(Employee.PROP_EMP_BENEFIT_TYPE,
				FetchMode.JOIN);
		detachedCriteria
				.setFetchMode(Employee.PROP_EMP_BENEFIT, FetchMode.JOIN);
		detachedCriteria
				.setFetchMode(Employee.PROP_EMP_DEPT_NO, FetchMode.JOIN);
		detachedCriteria.add(Restrictions.in(Employee.PROP_ID, empIds));
		List empList = salaryconfDAO.findByCriteria(detachedCriteria);
		return empList;
	}

	public List getAllEmpsalaryconfig() {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empsalaryconfig.class);
		detachedCriteria.addOrder(Order.asc(Empsalaryconfig.PROP_ID));
		return salaryconfDAO.findByCriteria(detachedCriteria);
	}

	public IStatusDAO getStatusDAO() {
		return statusDAO;
	}

	public void setStatusDAO(IStatusDAO statusDAO) {
		this.statusDAO = statusDAO;
	}

	public ISalaryconfDAO getSalaryconfDAO() {
		return salaryconfDAO;
	}

	public void setSalaryconfDAO(ISalaryconfDAO salaryconfDAO) {
		this.salaryconfDAO = salaryconfDAO;
	}

	private ISalaryconfDAO salaryconfDAO;
	private IStatusDAO statusDAO;
}
